﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ERP_RORZE_DLL.Assembly
{
    public partial class intem_AssemblyCheckSerial : UserControl
    {
        public int funcID;
        public bool showform;
        
        private DataSet ds;
        private DataViewManager dsView;

        public intem_AssemblyCheckSerial()
        {
            InitializeComponent();
            this.ds = new DataSet("RobotOrderDetail");

            this.funcID = 0;            
            this.showform = true;            
        }

        public void CreateData(DataSet myDataSet)
        {
            this.ds = myDataSet;
            this.dsView = ds.DefaultViewManager;

            this.serialNo.DataSource = dsView;
            this.serialNo.DisplayMember = "RobotOrderDetail.SerialNo";
            this.serialNo.ValueMember = "RobotOrderDetail.SerialNo";
            this.serialNo.AutoCompleteSource = AutoCompleteSource.ListItems;

            this.partNo.DataBindings.Add("Text", dsView, "RobotOrderDetail.CompID");
        }        

        public void setLabel(string label)
        {
            this.itemLabel.Text = label + ":";
        }

        public void setValue(string value)
        {
            if (this.serialNo.FindString(value) > 0)
            {
                this.serialNo.SelectedIndex = this.serialNo.FindString(value);
            }
        }

        public string getSerial()
        {
            string ret = null;
            if (this.serialNo.SelectedIndex >= 0)
            {
                ret = this.serialNo.SelectedValue.ToString().Trim();
            }
            return ret;
        }

        public string getPartNo()
        {
            string ret = null;
            if (this.serialNo.SelectedIndex >= 0)
            {
                ret = this.partNo.Text.Trim();
            }
            return ret;
        }

        public string getFuncName()
        {
            return this.itemLabel.Text;
        }

        public void removeValue(string value)
        {
            DataRow[] remove_rows = ds.Tables["RobotOrderDetail"].Select("SerialNo = '" + value + "'");
            if (remove_rows.Length > 0)
            {
                foreach (DataRow remove_row in remove_rows)
                {
                    ds.Tables["RobotOrderDetail"].Rows.Remove(remove_row);                    
                }
            }

            this.serialNo.SelectedIndex = 0;
        }
    }
}
